package com.huawei.appgallery.foundation.ui.css.adapter.type;

import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.StateListDrawable;
import java.lang.reflect.Array;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;

public class CSSColorList extends CSSColor {
    public static final int STATE_DEFAULT = -1;
    private Map<Integer, CSSMonoColor> colorList = new LinkedHashMap();

    public CSSColorList add(int i, CSSMonoColor cSSMonoColor) {
        this.colorList.put(Integer.valueOf(i), cSSMonoColor);
        return this;
    }

    public CSSColor getColor(int i) {
        return (CSSColor) this.colorList.get(Integer.valueOf(i));
    }

    public Map<Integer, CSSMonoColor> getColor() {
        return this.colorList;
    }

    public ColorStateList toColorStateList() {
        int size = this.colorList.size();
        if (size == 0) {
            return null;
        }
        int[][] iArr = (int[][]) Array.newInstance(Integer.TYPE, new int[]{size, 1});
        int[] iArr2 = new int[size];
        int i = 0;
        for (Entry entry : this.colorList.entrySet()) {
            if (((Integer) entry.getKey()).intValue() == -1) {
                iArr[i] = new int[0];
            } else {
                iArr[i] = new int[]{((Integer) entry.getKey()).intValue()};
            }
            iArr2[i] = ((CSSMonoColor) entry.getValue()).getColor();
            i++;
        }
        return new ColorStateList(iArr, iArr2);
    }

    public StateListDrawable toStateListDrawable() {
        StateListDrawable stateListDrawable = new StateListDrawable();
        for (Entry key : this.colorList.entrySet()) {
            int[] iArr = new int[]{((Integer) key.getKey()).intValue()};
            stateListDrawable.addState(iArr, new ColorDrawable(((CSSMonoColor) ((Entry) r3.next()).getValue()).getColor()));
        }
        return stateListDrawable;
    }
}
